import {toast} from "vue3-toastify";

export const getESS = (uid, onMessage, onOpen = () => console.log('SSE连接成功'), onClose = () => console.log('SSE连接出错')) => {
    let eventSource = null;
    if (window.EventSource) {
        eventSource = new EventSource('/api/sse/createSse?uid=' + uid);
        eventSource.onopen = (e) => onOpen(e);
        eventSource.onmessage = (e) => onMessage(e);
        eventSource.onerror = (e) => onClose(e);
    } else {
        toast('你当前浏览器不支持查看日志！', {autoClose: 2000, type: 'error'});
    }
    return eventSource;
}